Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ur-sdk): Add V4 Parser to UR parser #147

Merged
merged 8 commits into from
Oct 4, 2024
Merged

Conversation

marktoda
Copy link
Collaborator

@marktoda marktoda commented Oct 3, 2024

This commit merges in the v4 parser as a subparser for UR calldata.

PR Scope

Please title your PR according to the following types and scopes following conventional commits:

  • fix(SDK name): will trigger a patch version
  • chore(<type>): will not trigger any release and should be used for internal repo changes
  • <type>(public): will trigger a patch version for non-code changes (e.g. README changes)
  • feat(SDK name): will trigger a minor version
  • feat(breaking): will trigger a major version for a breaking change

Description

[Summary of the change, motivation, and context]

How Has This Been Tested?

[e.g. Manually, E2E tests, unit tests, Storybook]

Are there any breaking changes?

[e.g. Type definitions, API definitions]

If there are breaking changes, please ensure you bump the major version Bump the major version (by using the title feat(breaking): ...), post a notice in #eng-sdks, and explicitly notify all Uniswap Labs consumers of the SDK.

(Optional) Feedback Focus

[Specific parts of this PR you'd like feedback on, or that reviewers should pay closer attention to]

(Optional) Follow Ups

[Things that weren't addressed in this PR, ways you plan to build on this work, or other ways this work could be extended]

This commit merges in the v4 parser as a subparser for UR calldata.
Comment on lines +53 to +60
export type CommandDefinition =
| {
parser: Parser.Abi
params: ParamType[]
}
| {
parser: Parser.V4Actions
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've done a bit of a refactor here because we previously were not describing what was actually happening.

Universal Router command inputs are arbitrary bytes, that can mean anything but currently are either:

  • ABI encoded parameters for some action
  • direct calldata for a function on the V4 router or the V4 Position manager

Previously we were just describing the ABI, which was insufficient for actually expressing what was happening in the v4 case. This is why we had a hard-coded edge case in createCommand:

  if (type === CommandType.V4_SWAP) {
    return { type, encodedInput: parameters[0] }
  }

I've expanded the command inputs definition to capture this nuance, allowing different top level "parsers" for each command type's inputs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh interesting interesting, have you merged main? diana made some changes to that logic just this afternoon so want to make sure thats taken into account. But from what I can see youve already included that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I did! I made a separate V3Actions vs V4Actions, where both bypass the abi decoding

Copy link

graphite-app bot commented Oct 3, 2024

Graphite Automations

"Request reviewers once CI passes on sdks monorepo" took an action on this PR • (10/03/24)

1 reviewer was added and 1 assignee was added to this PR based on 's automation.

},
]
const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC', 'USD Coin')
const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

@@ -127,3 +148,17 @@ export function parseV3PathExactOut(path: string): readonly V3PathItem[] {

return res
}

function v4RouterCallToParams(actions: readonly V4RouterAction[]): readonly Param[] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open to feedback on this remapping of names. The alternative was to keep command.params as a V4RouterAction object like

{
   actionName: SWAP_EXACT_IN,
   ActionType: V4Action.SWAP_EXACT_IN,
   params: [...[
}

opted for this to be more standardized with the other non-v4 command datas

@marktoda marktoda merged commit d22530b into main Oct 4, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants